<div style="background:D0FFDD; margin:5px 20px; font-size:18px; text-align:right;">
    <select name="year" id="year" style="width:100px;">
        <option value=""> Chọn năm... </option>
        <?php 
            $nam = range(2013,2030);
            foreach($nam as $k => $v)
            {
                if(isset($_GET['y']))
                {
                    $y = $_GET['y'];
                    $select = $y==$v ? "selected = 'selected'" : "";
                }
                echo " <option value=".$v." $select >Năm ".$v."</option> ";
            }
        ?>
    </select>
</div>
<table class="tbl" border="1" style="table-layout:auto; width:820px;" id="tb">
    <thead> 
        <tr style="font-size:13px;"> <td>STT</td> <td>Môn</td> <td>Số buổi</td> <td>Buổi dạy</td> <td> Lựa chọn </td> </tr>
    </thead>
    <tbody>
    <?php
        if(isset($_GET['y']))
            $year = $_GET['y'];
        else
            $year = 0;
        $q = mysql_num_rows(mysql_query(" SELECT id FROM schedule WHERE year = {$year} "));
        if($q > 0)
            $query = mysql_query(" SELECT a.id, a.name, b.num_day, b.day, b.year FROM subject a left join schedule b on a.id = b.subject
                                   WHERE a.name != '' AND b.year = {$year} ORDER BY a.name ");
        else
            $query = mysql_query(" SELECT a.id, a.name, b.num_day, b.day, b.year FROM subject a left join schedule b on a.id = b.subject
                                   WHERE a.name != '' ORDER BY a.name ");
        if(mysql_num_rows($query) > 0)
        {
            $i=1;
            while($row = mysql_fetch_array($query))
            {
                echo "<tr style='height:50px;'>";
                    echo "<td> $i </td>";
                    echo "<td> ".$row['name']." </td>";
                    echo "<td> ".$row['num_day']." </td>";
                    echo "<td> ".$row['day']." </td>";
					echo "<td> <a href='' class='button'> Sửa buổi dạy </a> </td>";
                    $i++;
                echo "</tr>";	
            }
        }
        else
            echo "<tr> <td colspan='4'> Chưa có thời khóa biểu </td> </tr>";
    ?>
    </tbody>
</table>

<div style="text-align:center;">
    <input type="button" value="Xếp thời khóa biểu" id="xeplich" name="xeplich" class="button" style="width:200px;" /><span id="loader_action"></span></p>
</div>
<div id="result_action"> </div>